package contract.jvm;

import org.objectweb.asm.tree.AbstractInsnNode;

/**
 * 程序计数器（pc）
 */
public class ProgramCounter {

    /**
     * 当前指令
     */
    public AbstractInsnNode currentInsnNode;

    /**
     * 当前字节码
     */
    public OpCode currentOpCode() {
        if (currentInsnNode != null) {
            return OpCode.valueOf(currentInsnNode.getOpcode());
        }
        return null;
    }

    /**
     * 下一个字节码
     */
    public OpCode nextOpCode() {
        if (currentInsnNode != null) {
            currentInsnNode = currentInsnNode.getNext();
            while (currentInsnNode != null && currentInsnNode.getOpcode() < 0) {
                currentInsnNode = currentInsnNode.getNext();
            }
        }
        return currentOpCode();
    }

}
